# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sentinel-proxy
pkgver=2.1.0
pkgrel=0
pkgdesc="Proxy that relays messages received over ZMQ to Sentinel server over MQTT"
url="https://gitlab.nic.cz/turris/sentinel/proxy"
# s390x: blocked by czqm, logc-libs
arch="all !s390x"
license="GPL-3.0-or-later"
makedepends="
	argp-standalone
	autoconf-archive
	automake
	czmq-dev
	libconfig-dev
	libtool
	logc-dev
	logc-libs-dev
	msgpack-c-dev
	openssl-dev
	paho-mqtt-c-dev
	zlib-dev
	"
checkdepends="check-dev"
pkgusers="sentinel"
install="$pkgname.pre-install"
subpackages="
	$pkgname-dev
	$pkgname-openrc
	"
source="https://gitlab.nic.cz/turris/sentinel/proxy/-/archive/v$pkgver/proxy-v$pkgver.tar.bz2
	fix-configure-msgpack-c.patch
	example.cfg.patch
	$pkgname.initd
	$pkgname.confd
	"
builddir="$srcdir/proxy-v$pkgver"

prepare() {
	default_prepare

	./bootstrap
}

build() {
	defconfigfile="/etc/sentinel/proxy.cfg" \
	defzmqsockpath="/run/sentinel_pull.sock" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		$(want_check && echo '--enable-tests' || :)
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -D -m640 -o sentinel example.cfg "$pkgdir"/etc/sentinel/proxy.cfg

	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
8d21141c44bb638db6ec47054c2e9f1087ba39f5097d0c0f151ba160885687ec932e789d4c55f65e67a22fda65e2f83cf45bb125189c98161d0cbc621d462c0d  proxy-v2.1.0.tar.bz2
2586fdfee53a44f82a811b3959a8b771ea1733dd58ea9815ad5ef3d8061eca38dcd1c3d19f1876285ef7095d0ce558c9ccb6f11c4f9c6acf54721aaf834d611e  fix-configure-msgpack-c.patch
48dad43a27679396bbbe54013bd1487053c686b9872cfc49f744b6d005d43ff6c1c60dcd03b77f8970e1c13a1774cacbe2eb45bd116c28edc3b0173c28769bdf  example.cfg.patch
3e9e832994bf2574ae48dee6479a629d15bfdada86b89de95e5da1840f3312da0b19b697b94401783756917c8a5194a334807c44a6b23333369f57cab376010c  sentinel-proxy.initd
b3cd58a026b89ad60d5d93f88b549c67045b498134b67f4b06856e3be12b8debcf130937201b88543d3ba12cdfa1aab87cafa58f7c8c36215d41392d32eae5af  sentinel-proxy.confd
"
